import onloadHook from "../utils/onloadHook";
import request from "../utils/request";
export function timing() {
    onloadHook(function(){
        setTimeout(() => {
           let {
            fetchStart, 
            connectStart, 
            connectEnd,
            requestStart,
            responseStart,
            responseEnd,
            domainLookupStart,
            domainLookupEnd,
            domContentLoadedEventStart,
            domContentLoadedEventEnd,
            navigationStart
        } = performance.timing;

        let FP = performance.getEntries('paint').filter(entry => entry.name == 'first-paint')[0]?.startTime,
            FCP = performance.getEntries('paint').filter(entry => entry.name == 'first-contentful-paint')[0]?.startTime;
            
        request.send({
            kind: 'experience',
            type: 'timing',
            connectTime: connectEnd - connectStart,
            TTFB: responseStart - requestStart,
            DomReady:domContentLoadedEventEnd -navigationStart,
            parseDNS: domainLookupEnd  - domainLookupStart,
            FP,
            FCP
        })
        }, 3000);
    })
    
}